﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;
using System.IO;
using GameSPK.Model;
namespace GameSPK.DAO
{
    class NguoiChoiXMLDAO
    {
        public static Model.LabelLayout getNguoiChoiChung()
        {
            string fileXML = "layout/NguoiChoiLayout.xml";
            LabelLayout nguoichoichung = new LabelLayout();
            if (File.Exists(fileXML))
            {
                XElement layout = XElement.Load(fileXML);
                var home = (from c in layout.Elements()
                            where c.Name == "ChungNguoiChoi"
                            select c).Single();
                nguoichoichung.Width = double.Parse(home.Attribute("Width").Value);
                nguoichoichung.Height = double.Parse(home.Attribute("Height").Value);
                return nguoichoichung;
            }
            return null;
        }
        public static int getSoNguoiChoi()
        {
            return (int)CuocThiDAO.getCuocThiChon().SoNguoiChoi;
        }
        public static Model.LabelLayout getNguoiChoii(int index)
        {
            string fileXML = "layout/NguoiChoiLayout.xml";
            LabelLayout nguoichoi = new LabelLayout();
            if (File.Exists(fileXML))
            {
                XElement layout = XElement.Load(fileXML);
                XElement nguoichoilayout = layout.Element("NguoiChois");
                string tenThe = "NguoiChoi"+ index;
                var home = (from c in nguoichoilayout.Elements()
                            where c.Name == tenThe
                            select c).Single();
                
                nguoichoi.Top = double.Parse(home.Attribute("Top").Value);
                nguoichoi.Left = double.Parse(home.Attribute("Left").Value);
                nguoichoi.FontSize = double.Parse(home.Attribute("FontSize").Value);
                nguoichoi.sBackground = home.Attribute("BackGround").Value;
                nguoichoi.sForeground = home.Attribute("Foreground").Value;
                return nguoichoi;
            }
            return null;
        }

        public static Model.LabelLayout getButtonNext()
        {
            string fileXML = "layout/NguoiChoiLayout.xml";
            LabelLayout buttonNext = new LabelLayout();
            if (File.Exists(fileXML))
            {
                XElement layout = XElement.Load(fileXML);
                var home = (from c in layout.Elements()
                            where c.Name == "ButtonNext" 
                            select c).Single();
                buttonNext.Width = double.Parse(home.Attribute("Width").Value);
                buttonNext.Height = double.Parse(home.Attribute("Height").Value);
                buttonNext.Top = double.Parse(home.Attribute("Top").Value);
                buttonNext.Left = double.Parse(home.Attribute("Left").Value);
                
                return buttonNext;
            }
            return null;
        }
    }
}
